package com.imut.oa.controller.admin;

import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.PageResult;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.pojo.dto.LeavePageQueryDTO;
import com.imut.oa.pojo.dto.TaskDTO;
import com.imut.oa.pojo.dto.TaskPageQueryDTO;
import com.imut.oa.service.LeaveService;
import com.imut.oa.service.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/task")
@Slf4j
@Tag(name = "任务管理")
public class TaskController {
    @Autowired
    private TaskService taskService;
    @GetMapping("/page")
    @Operation(summary = "请假分页查询")
    public BaseResponse<PageResult> page (TaskPageQueryDTO taskPageQueryDTO){
        log.info("员工分页查询：{}",taskPageQueryDTO);
        PageResult pageResult = taskService.getTaskPage(taskPageQueryDTO);
        return ResultUtils.success(pageResult);
    }
    @PostMapping
    @Operation(summary = "添加任务")
    public BaseResponse addTask(@RequestBody TaskDTO taskDTO){
        log.info("添加任务：{}",taskDTO);
        taskService.addTask(taskDTO);
        return ResultUtils.success();
    }
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除任务记录")
    public BaseResponse<Integer> deleteById(@PathVariable Long id) {
        int result = taskService.deleteById(id);
        return ResultUtils.success(result);
    }

    @PostMapping("/cancel")
    @Operation(summary = "撤销任务发布")
    public BaseResponse<String> cancelLeave(@RequestParam("taskId") Long taskId) {
        log.info("撤销任务发布，任务ID：{}", taskId);
        taskService.cancelTask(taskId);
        return ResultUtils.success("撤销成功", "撤销成功");
    }
}
